﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Collections;
using System.Text.RegularExpressions;

namespace System.Web.Mvc {
	public class GridView<T> : IGridView<T> where T : class {
		private readonly TextWriter writer;
		private ViewContext context;

		/// <summary>
		/// Creates a new instance of the Grid class.
		/// </summary>
		/// <param name="dataSource">The datasource for the grid</param>
		/// <param name="writer">The TextWriter where the grid should be rendered</param>
		/// <param name="context"></param>
		public GridView(IEnumerable<T> dataSource, TextWriter writer, ViewContext context) {
			//this._gridModel = new GridModel<T>();
			this.writer = writer;
			this.context = context;
			this.DataSource = dataSource;
		}

		public IEnumerable<T> DataSource { get; private set; }

		/// <summary>
		/// Renders to the TextWriter, and returns null. 
		/// This is by design so that it can be used with inline syntax in views.
		/// </summary>
		/// <returns></returns>
		public override string ToString()
		{
			this.Render();
			return null;
		}

		public void Render()
		{
			this.writer.Write("aaaaaaaaaaa");
		}
	}

	public interface IGridView<T> : IGridViewWithOptions<T> where T : class
	{
		///// <summary>
		///// Specifies a custom GridModel to use.
		///// </summary>
		///// <param name="model">The GridModel storing information about this grid</param>
		///// <returns></returns>
		//IGridWithOptions<T> WithModel(IGridModel<T> model);
	}



	public interface IGridViewWithOptions<T> where T : class
	{
		///// <summary>
		///// Additional custom attributes
		///// </summary>
		///// <returns></returns>
		//IGridWithOptions<T> Attributes(IDictionary<string, object> attributes);

		///// <summary>
		///// Specifies the columns to use. 
		///// </summary>
		///// <param name="columnBuilder"></param>
		///// <returns></returns>
		//IGridWithOptions<T> Columns(Action<ColumnBuilder<T>> columnBuilder);

		///// <summary>
		///// Text to render when grid is empty.
		///// </summary>
		///// <param name="emptyText">Empty Text</param>
		///// <returns></returns>
		//IGridWithOptions<T> Empty(string emptyText);
		///// <summary>
		///// Additional custom attributes for the header row.
		///// </summary>
		///// <param name="attributes">Attributes for the header row</param>
		///// <returns></returns>
		//IGridWithOptions<T> HeaderRowAttributes(IDictionary<string, object> attributes);

		/// <summary>
		/// Renders the grid to the TextWriter specified at creation
		/// </summary>
		/// <returns></returns>
		void Render();

		///// <summary>
		///// Specifies that the grid should be rendered using a specified renderer.
		///// </summary>
		///// <param name="renderer">Renderer to use</param>
		///// <returns></returns>
		//IGridWithOptions<T> RenderUsing(IGridRenderer<T> renderer);
		///// <summary>
		///// Additional custom attributes for each row
		///// </summary>
		///// <param name="attributes">Lambda expression that returns custom attributes for each row</param>
		///// <returns></returns>
		//IGridWithOptions<T> RowAttributes(Func<GridRowViewData<T>, IDictionary<string, object>> attributes);

		///// <summary>
		///// The GridModel that holds the internal representation of this grid.
		///// </summary>
		//[EditorBrowsable(EditorBrowsableState.Never)]
		//IGridModel<T> Model { get; }
	}


}